package edu.sctu.practice.class01.huangtianlin.assign6.guava;

import com.google.common.base.Charsets;
import com.google.common.io.Files;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;


import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;

/**
 * Created by Administrator on 2015/11/26.
 */
public class Client {

    public static void main(String[] args) {


        String url = "http://tkpic.tukucc.com/4700/20140924/c_169578/";

        try {

           Document document =  Jsoup.connect(url).get();

            Elements elements = document.select("dd > a");

            for(Element element : elements){

                String title = element.text();

                String detailUrl  = element.attr("href");


                System.out.println(element.text());
                System.out.println(element.attr("href"));

                Files.append(element.text() + "-" + element.attr("href"), new File("D:\\456.txt"), Charsets.UTF_8);
                Files.append("\r\n", new File("D:\\456.txt"), Charsets.UTF_8);



                getContent(title,detailUrl);







            }


//            System.out.println(document);


        } catch (IOException e) {
            e.printStackTrace();
        }


    }

    private static void getContent(String title, String detailUrl) {

        try {
            Document document = Jsoup.connect("http://www.bxwx.org/b/70/70093/"+detailUrl).get();

            Element element = document.select("div#content").get(0);
            String content = element.text();

            Files.write(content.getBytes(),new File("D:\\xiaoshuo\\"+title+".txt"));



        } catch (IOException e) {
            e.printStackTrace();
        }


    }


}
